import 'package:dartx/dartx.dart';
import 'package:gluz/app/common/extension/string_extension.dart';
import 'package:gluz/generated/json/base/json_field.dart';
import 'package:gluz/generated/json/shop_detail_entity.g.dart';
import 'dart:convert';
export 'package:gluz/generated/json/shop_detail_entity.g.dart';

@JsonSerializable()
class ShopDetailEntity {
	String id = '';
	int skuId = 0;
	int spuId = 0;
	String userId = '';
	String skuName = '';
	String spuName = '';
	int classId = 0;
	String className = '';
	String allClassName = '';
	int brandId = 0;
	String brandName = '';
	String suppName = '';
	String suppCode = '';
	int venderId = 0;
	int salesPrice = 0;
	String salesCurrency = '';
	int stockNum = 0;
	int stockStateType = 0;
	String stockStateDesc = '';
	int isAreaRestrict = 0;
	int thirdSkuSource = 0;
	int skuState = 0;
	int skuType = 0;
	int selfSellType = 0;
	int saleModel = 0;
	String mainPicUrl = '';
	int lowestBuy = 0;
	String deliveryTime = '';
	int logisticsType = 0;
	int logisticsState = 0;
	int collectionsTotal = 0;
	String createdTime = '';
	String updatedTime = '';
	String currencyUnit = '';
	String minOrderQuantity = '';
	String wholesalePrice = '';
	String totalStock = '';
	String shippingAddress = '';
	String productDescription = '';
	int isConsignment = 0;
	int pageView = 0;
	String userName = '店铺名称';
	String userImg = '';
	String userCountry = '0';
	String memberLevel = '1';
	int isSample = 0;
	List<ShopDetailDetail> detail = [];
	List<ShopDetailImages> images = [];

	ShopDetailEntity();

	factory ShopDetailEntity.fromJson(Map<String, dynamic> json) => $ShopDetailEntityFromJson(json);

	Map<String, dynamic> toJson() => $ShopDetailEntityToJson(this);

	@override
	String toString() {
		return jsonEncode(this);
	}

	String saleModelString() {
		switch (saleModel) {
			case 0:
				return '自营';
			case 1:
				return '厂直';
			case 2:
				return 'POP';
		}
		return '自营';
	}
}

@JsonSerializable()
class ShopDetailDetail {
	String id = '';
	int productId = 0;
	String skuName = '';
	dynamic skuVideo;
	String saleUnit = '';
	String weight = '0';
	String productArea = '';
	String wareInfo = '';
	String seoModel = '';
	String taxCode = '';
	String capacity = '';
	String warrantDesc = '';
	int taxRatePercentage = 0;
	String specificParam = '';
	String introduce = '';
	String introducePc = '';
	String introduceApp = '';
	String introduceWechat = '';
	String createdTime = '';
	String updatedTime = '';
	String productColor = '';
	String unitVolume = '1';

	ShopDetailDetail();

	factory ShopDetailDetail.fromJson(Map<String, dynamic> json) => $ShopDetailDetailFromJson(json);

	Map<String, dynamic> toJson() => $ShopDetailDetailToJson(this);

	@override
	String toString() {
		return jsonEncode(this);
	}

	List<String> getIntroduceImages() {
		List<String> images = [];
		if (introduceWechat.isEmpty) return images;
		List<dynamic> imgs = jsonDecode(introduceWechat);
		for (var e in imgs) {
			e = 'http:$e';
			images.add(e);
		}
		return images;
	}

}

@JsonSerializable()
class ShopDetailImages {
	String id = '';
	int productId = 0;
	String url = '';
	// 0和1为图片，2为视频
	String type = '';
	int sortOrder = 0;
	String createdAt = '';

	String getPicUrl() {
		return url.jdImgFullUrl();
	}
	ShopDetailImages();

	factory ShopDetailImages.fromJson(Map<String, dynamic> json) => $ShopDetailImagesFromJson(json);

	Map<String, dynamic> toJson() => $ShopDetailImagesToJson(this);

	@override
	String toString() {
		return jsonEncode(this);
	}
}